
import '../model/travel_model.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
var Params = {
  "districtId": -1,
  "groupChannelCode": "RX-OMF",
  "type": null,
  "lat": -180,
  "lon": -180,
  "locatedDistrictId": 0,
  "pagePara": {
    "pageIndex": 1,
    "pageSize": 10,
    "sortType": 9,
    "sortDirection": 0
  },
  "imageCutType": 1,
  "head": {'cid': "09031014111431397988"},
  "contentType": "json"
};

class TravelDao{
  static Future<TravelItemModel> fetch(String urlStr,Map params,String groupChannelCode,int pageIndex, int pageSize) async{
   if (params.containsKey('pagePara')){
     Map map = params['pagePara'];
     map['pageIndex'] = pageIndex;
     map['pageSize'] = pageSize;
     map['groupChannelCode'] = groupChannelCode;

   }
    var url = Uri.parse(urlStr);
    final response = await http.post(url,body: jsonEncode(params));
    if(response.statusCode == 200){
      Utf8Decoder utf8decoder = Utf8Decoder();
      final result = json.decode(utf8decoder.convert(response.bodyBytes));
      TravelItemModel model =  TravelItemModel.fromJson(result);

      return model;
    }else {
      throw Exception('flutter_app/json/home_page.json 接口异常');
    }
  }
}